﻿using System;
using System.Collections.Generic;
using System.Reflection;

namespace SX.Utils
{
    
    public static class CustomAttributeExtensions
    {
        //public static IEnumerable<T> GetCustomAttributes<T>(this Assembly element) where T : Attribute
        //{
        //    foreach (T a in Attribute.GetCustomAttributes(element, typeof(T)))
        //    {
        //        yield return a;
        //    }
        //}

        //public static IEnumerable<T> GetCustomAttributes<T>(this MemberInfo element, bool inherit) where T : Attribute
        //{
        //    foreach (T a in Attribute.GetCustomAttributes(element, typeof(T), inherit))
        //    {
        //        yield return a;
        //    }
        //}
        /// <summary>
        /// 是否定义Attibute
        /// </summary>
        /// <param name="type"></param> 
        /// <returns></returns>
        public static bool IsDefined<T>(this Type type) where T : Attribute
        {
            return type.IsDefined(typeof(T));
        }
        /// <summary>
        /// 是否定义Attibute
        /// </summary>
        /// <param name="element"></param>
        /// <param name="attributeType"></param>
        /// <returns></returns>
        public static bool IsDefined<T>(this MethodInfo element) where T : Attribute
        {
            return element.IsDefined(typeof(T));
        }
        /// <summary>
        /// 是否定义Attibute
        /// </summary>
        /// <param name="element"></param>
        /// <param name="attributeType"></param>
        /// <returns></returns>
        public static bool IsDefined<T>(this MemberInfo element) where T : Attribute
        {
            return element.IsDefined(typeof(T));
        }
        /// <summary>
        /// 是否定义Attibute
        /// </summary>
        /// <param name="element"></param> 
        /// <returns></returns>
        public static bool IsDefined<T>(this ParameterInfo element) where T : Attribute
        {
            return element.IsDefined(typeof(T));
        }

        ///// <summary>
        ///// 是否定义Attibute
        ///// </summary>
        ///// <param name="type"></param>
        ///// <param name="attributeType"></param>
        ///// <returns></returns>
        //public static bool IsDefined(this Type type, Type attributeType)
        //{
        //    return Attribute.IsDefined(type, attributeType);
        //}

        ///// <summary>
        ///// 是否定义Attibute
        ///// </summary>
        ///// <param name="element"></param>
        ///// <param name="attributeType"></param>
        ///// <returns></returns>
        //public static bool IsDefined(this MemberInfo element, Type attributeType)
        //{
        //    return Attribute.IsDefined(element, attributeType);
        //}
        ///// <summary>
        ///// 是否定义Attibute
        ///// </summary>
        ///// <param name="element"></param>
        ///// <param name="attributeType"></param>
        ///// <returns></returns>
        //public static bool IsDefined(this ParameterInfo element, Type attributeType)
        //{
        //    return Attribute.IsDefined(element, attributeType);
        //}
    }
}
